<?php
require_once './common.php';
$title="控制台";
include ('./head.php');
echo '<div class="header">
        <ul class="nav nav-pills pull-right" role="tablist">
          <li role="presentation" class="active"><a href="../index.php">首页</a></li>
          <li role="presentation"><a href="../index.php?action=my">用户中心</a></li>
          <li role="presentation"><a href="../login.php?action=logout">退出</a></li>
        </ul>
        <h3 class="text-muted" align="left">控制台</h3>
      </div><hr>';


	$w_user=daddslashes($_COOKIE['w_user']);
	$sql = "SELECT * FROM w_user WHERE username='{$w_user}'";
	$sth = $db->query($sql);
	$result = $sth->fetch();
	
	if($_COOKIE['w_userid']!=userid($result[username],$key,$result[pwd])){
		setcookie("w_user", "", time()-3600*24*30);
		setcookie("w_userid", "", time()-3600*24*30);
		echo '登陆信息有误，3秒后跳转到登陆页...<br />若无法跳转请<a href="../login.php">点击这里进入</a><meta http-equiv="refresh" content="3;url=../login.php">';
		include ('include/foot.php');
	}else{
		if(isset($_POST['qq'])&&($_GET['action']==add)){
			$qq=daddslashes($_POST['qq']);
			$qpwd=daddslashes($_POST['qpwd']);
			$sid=daddslashes($_POST['sid']);
			$skey=daddslashes($_POST['skey']);
			$upsid=0;
			$gq=daddslashes($_POST['gq']);
			$t1=daddslashes($_POST['t1']);
			$t2=daddslashes($_POST['t2']);
			$dz=daddslashes($_POST['dz']);
			$pl=daddslashes($_POST['pl']);
			$pldata=daddslashes($_POST['pldata']);
			$shuo=0;
			$sname=daddslashes($_POST['sname']);
			$sdata=daddslashes($_POST['sdata']);
			$sfile=daddslashes($_POST['sfile']);
			$time=time();
			$id=$result[id];
			$vip=$result[vip];
			if($qq==""){
			echo 'QQ号不能为空！3秒后重新提交...<br />若无法跳转请<a href="add.php?qq='.$qq.'&sid='.$sid.'">点击这里进入</a><meta http-equiv="refresh" content="3;url=add.php?qq='.$qq.'&sid='.$sid.'">';
			}elseif($sid=="")
			{
			echo 'SID不能为空！3秒后重新提交...<br />若无法跳转请<a href="add.php?qq='.$qq.'&sid='.$sid.'">点击这里进入</a><meta http-equiv="refresh" content="3;url=add.php?qq='.$qq.'&sid='.$sid.'">';
			}else{
			$sqlc = "SELECT * FROM `w_qq` WHERE qq='{$qq}'";
			$sthc = $db->query($sqlc);
			if(!$sthc->fetch()){
				$q_sql = "SELECT * FROM `w_qq` WHERE id='{$id}'";
				$q_sth = $db->query($q_sql);
				$q_num = $q_sth->rowCount();
				if($vip||($q_num<1)){
					$sql = $qpwd?"INSERT INTO `w_qq`(`qq`, `qpwd`, `sid`,`skey`,`sidzt`,`skeyzt`, `zt`, `upsid`, `time`, `gq`, `t1`, `t2`, `dz`, `pl`, `pldata`, `shuo`, `sname`, `sdata`, `sfile`, `id`) VALUES ('{$qq}','{$qpwd}','{$sid}','{$skey}',0,0,'1','{$upsid}','{$time}','{$gq}','{$t1}','{$t2}','{$dz}','{$pl}','{$pldata}','{$shuo}','{$sname}','{$sdata}','{$sfile}','{$id}')":"INSERT INTO `w_qq`(`qq`, `sid`,`skey`,`sidzt`,`skeyzt`, `zt`,  `upsid`, `time`, `gq`, `t1`, `t2`, `dz`, `pl`, `pldata`, `shuo`, `sname`, `sdata`, `sfile`, `id`) VALUES ('{$qq}','{$sid}','{$skey}',0,0,'1','{$upsid}','{$time}','{$gq}','{$t1}','{$t2}','{$dz}','{$pl}','{$pldata}','{$shuo}','{$sname}','{$sdata}','{$sfile}','{$id}')";
					$count = $db->exec($sql);
					if($count) echo '添加成功！<br>你的配置信息已经保存，系统会持续操作您的空间动态，现在可以关闭浏览器。';
					else echo '添加失败！3秒后重新提交...<br />若无法跳转请<a href="add.php?qq='.$qq.'&sid='.$sid.'">点击这里进入</a><meta http-equiv="refresh" content="3;url=add.php?qq='.$qq.'&sid='.$sid.'">';
				}else{
					echo '添加失败！<br />普通会员只能添加一个体验账号<br />3秒后重跳到购买界面...<br />若无法跳转请<a href="../index.php?action=shop">点击这里进入</a><meta http-equiv="refresh" content="3;url=../index.php?action=shop">';
				}
			}else{
				$sql = $qpwd?"UPDATE `w_qq` SET `qpwd`='{$qpwd}',`sid`='{$sid}',`skey`='{$skey}',`skeyzt`='0',`sidzt`='0',`zt`='1',`upsid`='{$upsid}',`gq`='{$gq}',`t1`='{$t1}',`t2`='{$t2}',`dz`='{$dz}',`pl`='{$pl}',`pldata`='{$pldata}',`shuo`='{$shuo}',`sname`='{$sname}',`sdata`='{$sdata}',`sfile`='{$sfile}' WHERE qq='{$qq}' AND id='{$id}'":"UPDATE `w_qq` SET `sid`='{$sid}',`skey`='{$skey}',`skeyzt`='0',`sidzt`='0',`zt`='1',`upsid`='{$upsid}',`gq`='{$gq}',`t1`='{$t1}',`t2`='{$t2}',`dz`='{$dz}',`pl`='{$pl}',`pldata`='{$pldata}',`shuo`='{$shuo}',`sname`='{$sname}',`sdata`='{$sdata}',`sfile`='{$sfile}' WHERE qq='{$qq}' AND id='{$id}'";
				$count = $db->exec($sql);
				if($count) echo '更新成功！<br>你的配置信息已经保存，系统会持续操作您的空间动态，现在可以关闭浏览器。';
				else echo '更新失败！3秒后重新提交...<br />若无法跳转请<a href="add.php?qq='.$qq.'&sid='.$sid.'">点击这里进入</a><meta http-equiv="refresh" content="3;url=add.php?qq='.$qq.'&sid='.$sid.'">';
			}
			}
		}else{
		echo <<<HTML
		<h3 class="form-signin-heading">高级配置</h3>
		<form action="add.php?action=add" class="form-sign" method="post">
		QQ号码:<br><input type="text" class="form-control" name="qq" value="{$_GET['qq']}"><br>
		<input type="hidden" name="qpwd" value="{$_GET['p']}">
		SID:<br><input type="text" class="form-control" name="sid" value="{$_GET['sid']}"><br>
		SKEY:<br><input type="text" class="form-control" name="skey" value="{$_GET['skey']}"><br>
		<a href="getsid.php?action=getsid&qq={$_GET['qq']}&p={$_GET['p']}" class="btn btn-default btn-block">更新SID/SKEY</a><br>
		
		
		<label for="ck4" class="form-control">
		<input id="ck4" type="checkbox" name="gq" value="1">开启在线挂QQ
		</label><br>
		选择时段(全天挂Q请填"0000~2400")<br>
		<div class="input-group">
		<input type="text" name="t1" value="0000" placeholder="开始时间(h)" class="form-control">
		<span class="input-group-addon">~</span>
		<input type="text" name="t2" value="2400" placeholder="结束时间(h)" class="form-control">
		</div><br>
		
		<label for="ck1" class="form-control">
		<input id="ck1" type="checkbox" name="dz" value="1" checked=true>开启自动点赞</label><br>
		<label for="ck2" class="form-control">
		<input id="ck2" type="checkbox" name="pl" value="1" checked=true>开启自动评论</label><br>
		评论内容(支持匹配[语录]、[伤感语录]、[社会语录]、[时间],为空则匹配[随机])<br>
		<input type="text" class="form-control" name="pldata" value=""><br>
		<input type="submit" class="btn btn-primary btn-block" name="submit" value="提交">
		</form>
HTML;
		}
		
	}
	

include ('./foot.php');
exit;
?>